package com.zy.openchat.core.model.group;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

public class SuperGroupInfo implements Parcelable {
    //Group identifier
    public long id;
    public String username;
    //Number of members in the group
    public int member_count;
    //True, if the supergroup is a channel.
    public boolean is_channel;
    //True, if the supergroup or channel is verified.
    public boolean is_verified;

    //Status of the current user in the group
    public Group_ChatMemberStatus status;

    public boolean isPublicGroup(){
        return !TextUtils.isEmpty(username);
    }


    public boolean isMyGroup(){
        return status==null?false:status.isMyGroup();
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeString(this.username);
        dest.writeInt(this.member_count);
        dest.writeByte(this.is_channel ? (byte) 1 : (byte) 0);
        dest.writeByte(this.is_verified ? (byte) 1 : (byte) 0);
        dest.writeParcelable(this.status, flags);
    }

    public void readFromParcel(Parcel source) {
        this.id = source.readLong();
        this.username = source.readString();
        this.member_count = source.readInt();
        this.is_channel = source.readByte() != 0;
        this.is_verified = source.readByte() != 0;
        this.status = source.readParcelable(Group_ChatMemberStatus.class.getClassLoader());
    }

    public SuperGroupInfo() {
    }

    protected SuperGroupInfo(Parcel in) {
        this.id = in.readLong();
        this.username = in.readString();
        this.member_count = in.readInt();
        this.is_channel = in.readByte() != 0;
        this.is_verified = in.readByte() != 0;
        this.status = in.readParcelable(Group_ChatMemberStatus.class.getClassLoader());
    }

    public static final Creator<SuperGroupInfo> CREATOR = new Creator<SuperGroupInfo>() {
        @Override
        public SuperGroupInfo createFromParcel(Parcel source) {
            return new SuperGroupInfo(source);
        }

        @Override
        public SuperGroupInfo[] newArray(int size) {
            return new SuperGroupInfo[size];
        }
    };
}
